//权值线段树 + 离散化 - 查询[x, y]之间的数, 一共出现了多少次
//求逆序对个数
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define lc p << 1
#define rc p << 1 | 1
typedef long long ll;
const int N = 5e5 + 10;
ll a[N];
ll t[N];

struct node
{
    int l, r;
    ll cnt; //[l, r]之间的数出现的次数
}tr[N << 2];

void pushup(int p)
{
    tr[p].cnt = tr[lc].cnt + tr[rc].cnt;
}

void build(int p, int l, int r)
{
    tr[p] = {l, r, 0};
    if(l == r) return;
    int mid = (l + r) >> 1;
    build(lc, l, mid); build(rc, mid + 1, r);
    pushup(p);
}

ll query(int p, int x, int y)
{
    int l = tr[p].l, r = tr[p].r;
    if(x <= l && r <= y) return tr[p].cnt;
    int mid = (l + r) >> 1;
    ll sum = 0;
    if(x <= mid) sum += query(lc, x, y);
    if(y > mid) sum += query(rc, x, y);
    return sum;
}

//单点修改, x位置+1
void modify(int p, int x)
{
    int l = tr[p].l, r = tr[p].r;
    if(x == l && r == x) 
    {
        tr[p].cnt++;
        return;
    }
    int mid = (l + r) >> 1;
    if(x <= mid) modify(lc, x);
    else modify(rc, x);
    pushup(p);
}

int main()
{
    int n; cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        t[i] = a[i];
    }

    //离散化
    unordered_map<int, int> mp;
    sort(t + 1, t + 1 + n);
    int cnt = 0;
    for(int i = 1; i <= n; i++)
    {
        int x = t[i];
        if(mp.count(x)) continue;
        mp[x] = ++cnt;
    }

    build(1, 1, cnt);
    ll sum = 0;
    for(int i = 1; i <= n; i++)
    {
        //求[i + 1, cnt]之间数的个数
        int x = mp[a[i]];
        sum += query(1, x + 1, cnt);
        modify(1, x); //将a[i]添加到线段树中
    }
    cout << sum << endl;
    return 0;
}